/*
 * 统一API异常处理controller
 */
package com.smforj.ssm.modules.api.controller;

import org.apache.ibatis.logging.Log;
import org.apache.ibatis.logging.LogFactory;
import org.springframework.context.annotation.Scope;
import org.springframework.http.MediaType;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import com.smforj.ssm.frame.core.enums.RouterMapping;
import com.smforj.ssm.frame.core.web.controller.BaseControllerSupportImpl;
import com.smforj.ssm.frame.core.web.domain.DataResult;
 

/****
 * 统一API异常处理controller
 *
 * @author Haijun Gao 
 * @date 2017-4-28 下午4:10:27
 * @desp http://www.cnblogs.com/saga5998/
 * @email 573107773@qq.com
 */
@RouterMapping("")
@Controller
@RequestMapping("/api")
@Scope(value = "singleton")
public class ApiExceptionController extends BaseControllerSupportImpl {

    private static final Log logger = LogFactory.getLog(ApiExceptionController.class); 
 
    /****
     * 
     * @param id
     * @return
     * @date 2018年5月16日 上午11:13:19
     */
    @RequestMapping(value = {"/exception"}, method ={RequestMethod.GET},
            produces = MediaType.APPLICATION_JSON_VALUE)
    @ResponseBody
    public DataResult<String> getException(@ModelAttribute("ex") String exception, ModelMap model) {
    	if(logger.isDebugEnabled())
    		logger.debug("ApiExceptionController getException");
        DataResult<String> result = new DataResult<String>();  
        try{ 
        	result.addError(exception);
        }catch(Exception ex)
        {
        	logger.error(ex.getMessage());
        	result.addError("系统异常");
        }
        return result;
    } 
}
